<?php require_once(dirname(__FILE__)."/../config/config.php"); ?>
<?php 
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
$service=$_REQUEST['service'];
// 验证用户名是否存在
$sql="select * from zy_user where user_name = '".$username."' and password = '".$password."'";
$result=mysql_query($sql);
$rs=mysql_fetch_array($result);
if($rs==""){
    $error1=array("error1"=>"The username or password is wrong!");
    echo json_encode($error1);
}
//验证服务是否存在
$sql2="select * from zy_service where code = '".$service."'";
$result2=mysql_query($sql2);
$rs2=mysql_fetch_array($result2);
if($rs2==""){
    $error2=array("error2"=>"The service is not exist!");
    echo json_encode($error2);
    
}
//验证该用户是否购买该服务
if($rs['user_id']!="" && $rs2['service_id']!=""){
    $sql3="select * from zy_user_service where user_id = '".$rs['user_id']."' and service_id = '".$rs2['service_id']."'";
    $result3=mysql_query($sql3);
    $rs3=mysql_fetch_array($result3);
    if($rs3==""){
        $error3=array("error"=>"Sorry,The user doesn't order this service!");
        echo json_encode($error3);
    }else{
        //输出登录的用户名和密码
        $sql4="select * from zy_login_list where user_service_id ='".$rs3['id']."'";
        $result4=mysql_query($sql4);
        while($rs4=mysql_fetch_array($result4)){
        $array = array("username"=>$rs4['loginname'],"password"=>$rs4['loginpassword']);
        echo json_encode($array);
        }
    }
}
